package com.example.sensorscheck;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	private TextView mTextShow;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mTextShow = (TextView)findViewById(R.id.main_show_textview);
		
		SensorManager sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
		List<Sensor> allSensors = sm.getSensorList(Sensor.TYPE_ALL);
		
		StringBuffer sb = new StringBuffer();
		sb.append("该设备当中一共包含 " + allSensors.size() + " 种传感设备！\n");
		
		for(Sensor s : allSensors){
			String tmp = "\n" + "  设备名称：" + s.getName() + "\n" + "  设备版本：" + s.getVersion() + "\n" + "  供应商："
					 + s.getVendor() + "\n" ;
			
			switch (s.getType()) {
			case Sensor.TYPE_ACCELEROMETER:
				sb.append(s.getType() + " 加速度传感器Accelerometer" + tmp);
				break;
			case Sensor.TYPE_GYROSCOPE:
				sb.append(s.getType() + " 陀螺仪传感器Gyroscope" + tmp);
				break;
			case Sensor.TYPE_LIGHT:
				sb.append(s.getType() + " 环境光线传感器Light" + tmp);
				break;
			case Sensor.TYPE_MAGNETIC_FIELD:
				sb.append(s.getType() + " 电磁场传感器Magnetic field" + tmp);
				break;
			case Sensor.TYPE_PRESSURE:
				sb.append(s.getType() + " 压力传感器Pressure" + tmp);
				break;
			case Sensor.TYPE_PROXIMITY:
				sb.append(s.getType() + " 距离传感器Proximity" + tmp);
				break;
			case Sensor.TYPE_AMBIENT_TEMPERATURE:
				sb.append(s.getType() + " 温度传感器Temperature" + tmp);
				break;

			default:
				sb.append(s.getType() + " 未知传感器" + tmp);
				break;
			}
		}
		
		mTextShow.setText(sb.toString());
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
